home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Bitmap / Sources / Select.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  8.1 KB  |  298 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Select.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Bitmap.hpp"
  13.  
  14. #ifndef SELECT_H
  15. #include "Select.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef CONTENT_H
  27. #include "Content.h"
  28. #endif
  29.  
  30. // ----- Part Layer -----
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWITERS_H
  37. #include "FWIters.h"
  38. #endif
  39.  
  40. #ifndef FWPRESEN_H
  41. #include "FWPresen.h"
  42. #endif
  43.  
  44. #ifndef FWCONTXT_H
  45. #include "FWContxt.h"
  46. #endif
  47.  
  48. // ----- OS Layer -----
  49.  
  50. #ifndef FWPICTUR_H
  51. #include "FWPictur.h"
  52. #endif
  53.  
  54. #ifndef FWBARRAY_H
  55. #include "FWBArray.h"
  56. #endif
  57.  
  58. #ifndef FWODGEOM_H
  59. #include "FWODGeom.h"
  60. #endif
  61.  
  62. // ----- Foundation Layer -----
  63.  
  64. #ifndef FWSUSINK_H
  65. #include "FWSUSink.h"
  66. #endif
  67.  
  68. #ifndef FWMEMMGR_H
  69. #include "FWMemMgr.h"
  70. #endif
  71.  
  72. #ifndef FWMEMHLP_H
  73. #include "FWMemHlp.h"
  74. #endif
  75.  
  76. // ----- OpenDoc Includes -----
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdProps_defined
  79. #include <StdProps.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODShape_xh
  83. #include <Shape.xh>
  84. #endif
  85.  
  86. //========================================================================================
  87. //    Runtime Information
  88. //========================================================================================
  89.  
  90. #ifdef FW_BUILD_MAC
  91. #pragma segment odfbitmap
  92. #endif
  93.  
  94. //========================================================================================
  95. //    class CBitmapSelection
  96. //========================================================================================
  97.  
  98. FW_DEFINE_AUTO(CBitmapSelection)
  99.  
  100. //---------------------------------------------------------------------------------------
  101. //    CBitmapSelection::CBitmapSelection
  102. //---------------------------------------------------------------------------------------
  103.  
  104. CBitmapSelection::CBitmapSelection(Environment* ev, CBitmapPart* thePart, CBitmapContent* content) :
  105.     FW_CSelection(ev, FALSE, FALSE),
  106.     fBitmapPart(thePart),
  107.     fSelectedContent(NULL),
  108.     fHasSelection(false)
  109. {
  110.     fSelectedContent = new CBitmapSelectionContent(ev, thePart, this, content);
  111.  
  112.     fRectShape.GetStyle().SetPattern(FW_kAntPat);
  113.     fRectShape.GetInk().SetTransferMode(FW_kXOr);
  114.     fRectShape.SetRenderVerb(FW_kFrame);
  115.     
  116.     FW_END_CONSTRUCTOR
  117. }
  118.  
  119. //---------------------------------------------------------------------------------------
  120. //    CBitmapSelection::~CBitmapSelection
  121. //---------------------------------------------------------------------------------------
  122.  
  123. CBitmapSelection::~CBitmapSelection()
  124. {    
  125.     FW_START_DESTRUCTOR
  126.     
  127.     delete fSelectedContent;
  128. }
  129.  
  130. //---------------------------------------------------------------------------------------
  131. //    CBitmapSelection::CloseSelection
  132. //---------------------------------------------------------------------------------------
  133.  
  134. void CBitmapSelection::CloseSelection(Environment* ev)
  135. {
  136.     if (fHasSelection)
  137.     {
  138.         DrawAnts(ev, (CBitmapFrame*)fBitmapPart->GetLastActiveFrame(ev));    // Erase ants
  139.         fHasSelection = false;
  140.     }
  141. }
  142.  
  143. //---------------------------------------------------------------------------------------
  144. //    CBitmapSelection::ClearSelection
  145. //---------------------------------------------------------------------------------------
  146.  
  147. void CBitmapSelection::ClearSelection(Environment* ev)
  148. {
  149.     // Nothing to do
  150. }
  151.  
  152. //---------------------------------------------------------------------------------------
  153. //    CBitmapSelection::SelectAll
  154. //---------------------------------------------------------------------------------------
  155.  
  156. void CBitmapSelection::SelectAll(Environment* ev)
  157. {
  158.     // ----- Close the selection if there is one -----
  159.     CloseSelection(ev);
  160.     
  161.     // ----- Select entire bitmap -----
  162.     fSelectedContent->SelectEntireBitmap(ev);
  163.     fHasSelection = true;
  164.     
  165.     // ----- Draw the first ants -----
  166.     DrawAnts(ev, (CBitmapFrame*)fBitmapPart->GetLastActiveFrame(ev));
  167. }
  168.  
  169. //---------------------------------------------------------------------------------------
  170. //    CBitmapSelection::GetSelectedContent
  171. //---------------------------------------------------------------------------------------
  172.  
  173. FW_CContent* CBitmapSelection::GetSelectedContent(Environment* ev)
  174. {
  175.     return fSelectedContent;
  176. }
  177.  
  178. //---------------------------------------------------------------------------------------
  179. //    CBitmapSelection::IsEmpty
  180. //---------------------------------------------------------------------------------------
  181.  
  182. FW_Boolean CBitmapSelection::IsEmpty(Environment* ev) const
  183. {
  184.     return !fHasSelection;
  185. }
  186.  
  187. //---------------------------------------------------------------------------------------
  188. //    CBitmapSelection::MoveAnts
  189. //---------------------------------------------------------------------------------------
  190.  
  191. void CBitmapSelection::MoveAnts(Environment* ev, CBitmapFrame* frame)
  192. {
  193.     DrawAnts(ev, frame);
  194.     
  195.     FW_CStyle style = fRectShape.GetStyle();    
  196.     FW_CPattern pattern = style.GetPattern();
  197.     pattern.ShiftRight();
  198.     style.SetPattern(pattern);
  199.         
  200.     DrawAnts(ev, frame);
  201. }
  202.  
  203. //---------------------------------------------------------------------------------------
  204. //    CBitmapSelection::DrawAnts
  205. //---------------------------------------------------------------------------------------
  206. // Draw ants in all facets of the given frame.
  207.  
  208. void CBitmapSelection::DrawAnts(Environment* ev, CBitmapFrame* frame)
  209. {
  210.     if (frame != NULL)
  211.     {
  212.         FW_CFrameFacetIterator iter(ev, frame);
  213.         for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  214.         {
  215.             FW_CViewContext vc(ev, frame, facet);
  216.             DoDrawAnts(ev, vc, frame);
  217.         }
  218.     }
  219. }
  220.  
  221. //---------------------------------------------------------------------------------------
  222. //    CBitmapSelection::DoDrawAnts
  223. //---------------------------------------------------------------------------------------
  224.  
  225. void CBitmapSelection::DoDrawAnts(Environment* ev, FW_CGraphicContext& gc, CBitmapFrame* frame)
  226. {
  227.     FW_CRect usedRect;
  228.     frame->CalcUsedRect(ev, usedRect);
  229.  
  230.     FW_CRect rect;
  231.     GetSelectRect(frame->GetZoomRatio(ev), usedRect, rect);
  232.  
  233.     fRectShape.SetRectangle(rect);
  234.     fRectShape.Render(gc);
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    CBitmapSelection::CreateSelectionShape
  239. //----------------------------------------------------------------------------------------
  240.  
  241. ODShape* CBitmapSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
  242. {
  243.     ODShape* selectionShape = ::FW_NewODShape(ev, FW_kZeroRect);
  244.     
  245.     if (!IsEmpty(ev))
  246.     {
  247.         FW_CRect usedRect;
  248.         ((CBitmapFrame*)frame)->CalcUsedRect(ev, usedRect);
  249.     
  250.         FW_CRect selectRect;
  251.         GetSelectRect(((CBitmapFrame*)frame)->GetZoomRatio(ev), usedRect, selectRect);
  252.     
  253.         ODRect odSelectRect = selectRect;
  254.         selectionShape->SetRectangle(ev, &odSelectRect);
  255.     }
  256.     
  257.     return selectionShape;
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    CBitmapSelection::GetSelectRect
  262. //----------------------------------------------------------------------------------------
  263.  
  264. void CBitmapSelection::GetSelectRect(const FW_CPoint& ratio, const FW_CRect& usedRect, FW_CRect& rect) const
  265. {
  266.     if (fHasSelection)
  267.     {
  268.         FW_CPlatformRect selectRect;
  269.         fSelectedContent->GetSelectRect(selectRect);
  270.         rect.Set(
  271.             FW_MultipliedByInt(ratio.x, selectRect.left),
  272.             FW_MultipliedByInt(ratio.y, selectRect.top),
  273.             FW_MultipliedByInt(ratio.x, selectRect.right),
  274.             FW_MultipliedByInt(ratio.y, selectRect.bottom));
  275.     
  276.         rect.Offset(usedRect.left, usedRect.top);
  277.     }
  278.     else
  279.         rect.SetInt(0, 0, 0, 0);
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    CBitmapSelection::SetSelectRect
  284. //----------------------------------------------------------------------------------------
  285.  
  286. void CBitmapSelection::SetSelectRect(const FW_CPoint& ratio, const FW_CRect& usedRect, const FW_CRect& rect)
  287. {
  288.     FW_CPlatformRect selectRect(
  289.         FW_FixedToInt((rect.left  - usedRect.left) / ratio.x),
  290.         FW_FixedToInt((rect.top  - usedRect.top) / ratio.y),
  291.         FW_FixedToInt((rect.right  - usedRect.left) / ratio.x),
  292.         FW_FixedToInt((rect.bottom - usedRect.top) / ratio.y));
  293.     fHasSelection = TRUE;
  294.     fSelectedContent->SetSelectRect(selectRect);
  295. }
  296.  
  297.  
  298.